package test.db.table.mysql.type;

import com.geeksaga.crypt.TripleDes;

import test.db.table.Table;
import test.db.util.DBUtil;

/**
 * @author newbie
 * @since 0.1
 */
public enum PwUserTable implements Table, ColumnType {
    SID(Column.sid),
    PID(Column.pid),
    USER_ID(Column.userId),
    PASSWD(Column.passwd),
    GRADE(Column.grade),
    EMAIL(Column.email),
    USER_NAME(Column.userName),
    NICK_NAME(Column.nickName),
    IMG_FILE(Column.imgFile),
    ICON_FILE(Column.iconFile),
    ENABLED(Column.enabled),
    EXPIRED(Column.expired),
    CREDENTIAL(Column.credential),
    LOCKED(Column.locked);
    
    private final Column column;
    private static final String TYPE_PASSWD = "VARCHAR(32)";
    private static final String TYPE_GRADE = "INT(5)";
    private static final String TYPE_EMAIL = "VARCHAR(100)";
    private static final String TYPE_USER_NAME = "VARCHAR(64)";
    private static final String TYPE_NICK_NAME = "VARCHAR(64)";
    private static final String TYPE_IMG_FILE = "VARCHAR(128)";
    private static final String TYPE_ICON_FILE = "VARCHAR(128)";
    private static final String TYPE_ENABLED = "VARCHAR(1)";
    private static final String TYPE_EXPIRED = "VARCHAR(1)";
    private static final String TYPE_CREDENTIAL = "VARCHAR(1)";
    private static final String TYPE_LOCKED = "VARCHAR(1)";

    PwUserTable(Column column) {
        this.column = column;
    }
    
    private enum Column {
        sid {
            String getType() {
                return TYPE_SID;
            }
        },
        
        pid {
            String getType() {
                return TYPE_PID;
            }
        },
        
        userId {
            String getType() {
                return TYPE_USER_ID;
            }
        },
        
        passwd {
            String getType() {
                return TYPE_PASSWD;
            }
        },
        
        grade {
            String getType() {
                return TYPE_GRADE;
            }
        },
        
        email {
            String getType() {
                return TYPE_EMAIL;
            }
        },
        
        userName {
            String getType() {
                return TYPE_USER_NAME;
            }
        },
        
        nickName {
            String getType() {
                return TYPE_NICK_NAME;
            }
        },
        
        imgFile {
            String getType() {
                return TYPE_IMG_FILE;
            }
        },
        
        iconFile {
            String getType() {
                return TYPE_ICON_FILE;
            }
        },
        
        enabled {
            String getType() {
                return TYPE_ENABLED;
            }
        },
        
        expired {
            String getType() {
                return TYPE_EXPIRED;
            }
        },
        
        credential {
            String getType() {
                return TYPE_CREDENTIAL;
            }
        },
        
        locked {
            String getType() {
                return TYPE_LOCKED;
            }
        };
        
        abstract String getType();
    }
    
    public String getType() {
        return column.getType();
    }
    
    public void initData() throws Exception {
        DBUtil.addData("INSERT INTO PW_USER VALUES (100000000000000000, 'SAGA', 'administrator', '" + new TripleDes().encrypt("1234") + "', '100', 'smileemaker@gmail.com', 'Administrator', 'Administrator', '', '', '1', '1', '1', '1')");
        DBUtil.addData("INSERT INTO PW_USER VALUES (200912121212111111, 'SAGA', 'beta1', '" + new TripleDes().encrypt("1234") + "', '100', 'beta1@gmail.com', 'BETA-1', 'BETA-1', '', '', '1', '1', '1', '1')");
        DBUtil.addData("INSERT INTO PW_USER VALUES (200912121212111112, 'SAGA', 'beta2', '" + new TripleDes().encrypt("1234") + "', '100', 'beta2@gmail.com', 'BETA-2', 'BETA-1', '', '', '1', '1', '1', '1')");
    }
}